/**  
* @Title: CityServiceImpl.java  
* @Description: TODO(用一句话描述该文件做什么)  
* @author 张鑫
* @phone 17561783855  
* @date 2019年4月1日  
*/
package com.fortune.rainshine.common.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.fortune.rainshine.common.dao.CityMapper;
import com.fortune.rainshine.common.service.CityService;
import com.fortune.rainshinecommon.base.CityModel;
import com.fortune.rainshinecommon.base.MsgModel;
import com.fortune.rainshinecommon.enums.ResultCode;
import com.fortune.rainshinecommon.util.StringUtil;

/**  
* @ClassName: CityServiceImpl  
* @Description: TODO(这里用一句话描述这个类的作用)  
* @author 张鑫
* @phone 17561783855
* @date 2019年4月1日  
*    
*/
@Service
public class CityServiceImpl implements CityService{
	private final static Logger logger = LoggerFactory.getLogger(CityServiceImpl.class);
	@Autowired
    private CityMapper mapper;

	@Override
	public MsgModel getAreaList(CityModel model) {
		try {
			Wrapper<CityModel> wrapper = new EntityWrapper<>();
			if (StringUtil.isBlank(model.getParentId())) {
				wrapper.eq("level", "1");
				wrapper.ne("parent_id", '0');
				wrapper.orderBy("city_order", true);
			}else{
				wrapper.eq("parent_id", model.getParentId());
			}
			List<CityModel> list = mapper.selectList(wrapper);
			return new MsgModel(ResultCode.SUCCESS, list);
		} catch (Exception e) {
			e.printStackTrace();
			logger.info(e.toString());
			return new MsgModel(ResultCode.FAILURE);
		}
	}

	@Override
	public CityModel getCity(String code) {
		CityModel city = new CityModel();
		city.setCityCode(code);
		city = mapper.selectOne(city);
		return city;
	}

}
